package kr.hkit.powerjava.chapter24;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

public class ObjectStreamTest {
	public static void main(String[] args) {
		ObjectOutputStream oos = null;
		ObjectInputStream ois = null;
		try {
			oos = new ObjectOutputStream(new FileOutputStream("object.dat"));
			oos.writeObject(new Date()); //시리즈라이블 구현
			oos.flush(); //버퍼 지움
			
			
			ois = new ObjectInputStream(new FileInputStream("object.dat"));
			Date d = (Date) ois.readObject();
			System.out.println(d);
		
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			if(oos != null) try{oos.close();}catch(Exception e) {}
		}
	}
}